<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>网站配置 - bootstrap中文后台管理系统模板</title>
    <link href="/static/admin/css/bootstrap.min.css" rel="stylesheet">
    <link href="/static/admin/css/fonts.css" rel="stylesheet">
    <link href="/static/admin/css/style.css" rel="stylesheet">
</head>

<body>
<!--页面主要内容-->
<main class="ftdms-layout-content">
    <div class="container-fluid" style="margin-bottom:90px;">
        <div class="row" style="margin-top:15px;">
            <div class="col-lg-12">
                <div class="card">
                    <ul class="nav nav-tabs page-tabs">
                        <li><a href="/admin/ad">新增轮播</a></li>
                        <li class="active"><a href="javascript:void(0)">查看管理轮播</a></li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active">
                            <div class="table-responsive">
                                <table class="table table-hover">
                                    <thead>
                                    <tr>
                                        <th>#</th>
                                        <th>标题文本</th>
                                        <th>网址</th>
                                        <th>图片</th>
                                        <th>是否显示</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <#list ads as ad>
                                        <tr>
                                            <td>${ad.sort}/${ad_index+1}</td>
                                            <td>${ad.title}</td>
                                            <td>${ad.url}</td>
                                            <td><img src="/upload/ad/${ad.img}" width="200" alt=""></td>
                                            <td>
                                                <label class="ftdms-switch switch-solid switch-primary">
                                                    <input type="checkbox" name="shows" did="${ad.id}" value="${ad.shows?string("1","0")}" ${ad.shows?string("checked","")}>
                                                    <span></span>
                                                </label>
                                            </td>
                                            <td>
                                                <a href="/admin/ad?action=delete&id=${ad.id}&img=${ad.img}" class="btn del btn-xs btn-danger">删除</a>
                                                <a href="/admin/ad?action=edit&id=${ad.id}" class="btn del btn-xs btn-info">编辑</a>
                                            </td>
                                        </tr>
                                    <#else>
                                        <tr>
                                            <td colspan="100">无数据</td>
                                        </tr>
                                    </#list>
                                    </tbody>
                                </table>


                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
</main>
<!--End 页面主要内容-->
<script src="/static/jquery/jquery.min.js"></script>
<script>

    //设置显示和隐藏
    $(':checkbox[name=shows]').click(function () {
        let t = $(this);
        $.ajax({
            type: 'POST',
            url: '/admin/ad',
            data: {id: t.attr('did'), shows: t.val() == 0 ? true : false, action: "shows"},
            success: function (e) {
                //location.reload();
                t.val(t.val() == 0 ? 1 : 0);
                alert(e);
            }
        });
    });
</script>
</body>
</html>